package br.com.agenda.pages.usuario;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.BeanEditForm;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ComponentSource;

import br.com.agenda.dao.UsuarioDAO;
import br.com.agenda.entities.Usuario;

public class Cadastro {

	@PageActivationContext
	@Property
	//@Persist
	private Usuario usuario;
	
	@Inject
	private UsuarioDAO usuarioDAO;
	
	@Component
	private BeanEditForm beanEditForm;
	
	private ComponentResources componentResources;
	
	public void onSubmit(){
		gravar();
	}

	private void gravar() {
		String msg = null;
		msg=usuarioDAO.saveEncrypt(usuario);
		if(msg != null){
			beanEditForm.recordError(msg);
		}else{
			//limpar();
		}
	}

//	private void limpar() {
//		componentResources.discardPersistentFieldChanges();
//		
//	}
	
}
